package java6703.lesson01;
//超市类
import java.util.Arrays;
import java.util.Objects;

public class Market6703 {
    private String name;
    private Product6703[] productList;

    public Market6703(String name, Product6703[] productList) {
        this.name = name;
        this.productList = productList;
    }

    public Market6703() {
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Market6703 that = (Market6703) o;
        return Objects.equals(name, that.name) &&
                Arrays.equals(productList, that.productList);
    }



    @Override
    public String toString() {
        return "Market6703{" +
                "name='" + name + '\'' +
                ", productList=" + Arrays.toString(productList) +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Product6703[] getProductList() {
        return productList;
    }

    public void setProductList(Product6703[] productList) {
        this.productList = productList;
    }

    public Product6703 sell(String str){
        for (int i=0;i< productList.length;i++){
            if (str.equals(productList[i])){
                return productList[i];
            }
        }
        return  null;
    }
    public String sell(Product6703[] productList){
        String str ="";
        //用俩层for循环判断购物者的商品清单数组的每个商品是否在超市的商品清单数组里
        for (int i = 0; i < productList.length; i++) {
            for (int j = 0 ; j<this.productList.length; j++) {
                if (productList[i].getName().equals(this.productList[j].getName())) {

                    str +=productList[i].getName()+",";
                }
            }
        }
        str = str.substring(0, (str.length()-1));
        return str;
    }
}
